package com.keepmoving.web;

import com.keepmoving.po.Commit;
import com.keepmoving.service.CommitService;
import com.keepmoving.util.TrimUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 魏范彬
 * 评论控制器
 */
@Controller
public class CommitController {
    Logger logger=Logger.getLogger(CommitController.class);
    @Resource
    CommitService commitService;

    @RequestMapping("/tocommit")
    public String tocommit(){
        logger.info("进入留言");
        return "commit";
    }

    @RequestMapping("/commit")
    public String commit(@ModelAttribute Commit commit, Model model){
        commitService.insert(commit);
        List<Commit> list = commitService.findBylId(commit.getlId());
        model.addAttribute("commitlist",list);
        return "commitinfo";
    }

    @RequestMapping("/commitreply")
    public String commitreply(Model model, HttpSession session){
        System.out.println("----------------------------");
        Integer oId=(Integer)session.getAttribute("oId");
        System.out.println(oId);
        Commit commit = commitService.findById(oId);
        System.out.println(commit.toString());
        List<Commit> list = commitService.findBylId(commit.getlId());
        System.out.println("++++++++++++++++++++++++++");
        model.addAttribute("commitlist",list);
        return "commitinfo";
    }


}
